//
//  BudgetManagerItemView.swift
//  KoiAccounting
//
//  Created by 纪洪文 on 16.04.25.
//

import SwiftUI

struct BudgetManagerItemView: View {
    
    var budget: BudgetCombine
    
    var body: some View {
        HStack {
            CategoryIconView(item: budget.category)
            VStack {
                HStack {
                    Text(budget.category.name.orEmpty)
                        .font(.system(size: 14))
                        .foregroundColor(Color.koiColorTitle)
                    
                    Spacer()
                    Text("剩余")
                        .font(.system(size: 12))
                        .foregroundColor(Color.koiColorTitleSecond)
                    Text(budget.getSurplus().toStringWithoutTrailingZeros())
                        .font(.system(size: 13))
                        .foregroundColor(Color.koiColorTitle)
                }
                
                ProgressView(value: budget.getUsePercent())
                    .tint(Color.koiColorPrimary)
                
                HStack {
                    Text("预算 \(budget.getBudgetAmount().toStringWithoutTrailingZeros())")
                        .font(.system(size: 12))
                        .foregroundColor(Color.koiColorTitleSecond)
                    
                    Text("支出 \(budget.expenseAmount.toStringWithoutTrailingZeros())")
                        .font(.system(size: 12))
                        .foregroundColor(Color.koiColorTitleSecond)
                    
                    Spacer()
                    
                    Text(budget.getUsePercent().toPercent())
                        .font(.system(size: 12))
                        .foregroundColor(Color.koiColorTitleSecond)
                }
            }
        }
    }
}

#Preview {
    BudgetManagerItemView(budget: BudgetCombine(budget: AccountingBudget(), category: AccountingCategory(), expenseAmount: 1000))
}
